home *** CD-ROM | disk | FTP | other *** search
- /* Copyright ©November 1993, Dale Schaafsma All rights reserved */
- /* This is an xfcn for hyperdard which does the following:
- /* opens the microphone, waits until a "loud" sound, takes the next 1024 bytes
- /* runs a fast fourier trasform on the data, and calls if appropriate the script
- /* for the key hit on a touch tone phone */
- /************************************************************/
- /* many thanks to:
- /* the author of Sound Confusion (Copyright © 1992 Bernie Bernstein ) the source
- /* for the microphone
- /* Numerical recipies for the fft algorithm which finally worked
- /* and finally many authors of xcmd/xfcns who submitted their source for the
- /* hypercard interface of things */
-
- #include <types.h>
- #include <sound.h>
- #include <soundinput.h>
- #include <stdio.h>
- #include <math.h>
- #include <Memory.h>
- #include <HyperXcmd.h>
- #include <SetUpA4.h>
- #include <pascal.h>
-
- #include "record.h"
- Boolean phInitialized = false;
- Boolean error = false;
- Boolean mylock = false;
- StringPtr *phScripts[12];
- #define kUsageString "\pUsage:PhoneDecode <script0> <script1> .. <script9> <script*> <script#>"
-
- pascal void main(XCmdPtr paramPtr)
- {
- int err;
- long i=0,j=0,num=0;
- RememberA0();
- SetUpA4();
- /* catch error, initialized or exit */
- /* if exit, and initialized */
- if ((((**(paramPtr -> params[0])) == 'q') || ((**(paramPtr -> params[0])) == 'Q')) && phInitialized) {
- finishToneRecognize();
- paramPtr->returnValue = PasToZero(paramPtr,"\pDeallocated");
- phInitialized = false;
- goto out;
- }
- /* if error */
- if (error) {
- paramPtr->returnValue = PasToZero(paramPtr,"\pPhoneDecode: error occurred!");
- goto out;
- }
- /* if initialized use this as idle time */
- if (phInitialized && !mylock) {
- mylock = true;
- if ((err = toneRecognize(paramPtr)) != kNoError)
- paramPtr->returnValue = PasToZero(paramPtr,"\pError in tone");
- mylock = false;
- goto out;
- }
- else if (phInitialized && mylock) goto out;
-
- /* if not enough args pass back the usage or other info */
- if (paramPtr -> paramCount < 12) {
- if ((**(paramPtr -> params[0])) == '!') {
- paramPtr->returnValue = PasToZero(paramPtr,"\pThis xcmd should have accompanying docs\n\
- Written by Dale Schaafsma, FREEware!");
- goto out;
- }
- else {
- paramPtr->returnValue = PasToZero(paramPtr,kUsageString);
- goto out;
- }
- }
-
- /* start initializing */
- else {
- if ((err = initToneRecognize()) != kNoError) {
- switch (err) {
- case kNoInput:
- paramPtr->returnValue = PasToZero(paramPtr,"\pNo Input");
- break;
- case kGestaltFailed:
- paramPtr->returnValue = PasToZero(paramPtr,"\pGestalt Failed");
- break;
- case kOpeningDevice:
- paramPtr->returnValue = PasToZero(paramPtr,"\pOpen Device Failed");
- break;
- case kGettingRate:
- paramPtr->returnValue = PasToZero(paramPtr,"\pError Getting Rate");
- break;
- case kMemory:
- paramPtr->returnValue = PasToZero(paramPtr,"\pMemory Error");
- break;
- case kBufSetup:
- paramPtr->returnValue = PasToZero(paramPtr,"\pError Setting Up Buffers");
- break;
- default:
- paramPtr->returnValue = PasToZero(paramPtr,"\pError Initializing ToneRecognize");
- break;
- }
- error = true;
- goto out;
- }
- /* actually grab the script names the user wants to use */
- for(i=0; i<12; i++) {
- phScripts[i] = (StringPtr) NewHandle(strlen(*(paramPtr -> params[i])));
- strcpy(*(phScripts[i]), (*(paramPtr -> params[i])));
- }
-
- paramPtr->returnValue = PasToZero(paramPtr,"\pInitialized");
- phInitialized = true;
- goto out;
- }
- out:
- RestoreA4();return;
- }